import path from 'node:path'
import { fileURLToPath } from 'node:url'
import js from '@eslint/js'
import { FlatCompat } from '@eslint/eslintrc'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
  baseDirectory: __dirname,
  recommendedConfig: js.configs.recommended,
  allConfig: js.configs.all
})

export default [
  ...compat.extends('plugin:vue/vue3-essential', 'eslint:recommended', '@vue/eslint-config-typescript', '@vue/eslint-config-prettier'),
  {
    languageOptions: {
      globals: {
        uni: true,
        wx: true,
        WechatMiniprogram: true,
        getCurrentPages: true,
        getApp: true,
        UniApp: true,
        UniHelper: true,
        App: true,
        Page: true,
        Component: true,
        AnyObject: true
      },

      ecmaVersion: 'latest',
      sourceType: 'module'
    },

    rules: {
      'prettier/prettier': [
        'warn',
        {
          semi: false, // 句尾是否填加分号
          singleQuote: true, //是否使用单引号
          printWidth: 180, //每行代码的限制长度
          trailingComma: 'none', //禁止随时添加逗号
          endOfLine: 'auto', // 结尾是 \n \r \n\r
          vueIndentScriptAndStyle: true
        }
      ],

      // https://eslint.vuejs.org/
      'vue/multi-word-component-names': ['off'], // 防止template模板报错
      'vue/no-deprecated-html-element-is': ['off'], // 不允许在 HTML 元素上使用已弃用的 is 属性
      // https://typescript-eslint.io/rules/
      '@typescript-eslint/no-unused-vars': ['off'], // 禁止未使用的变量
      '@typescript-eslint/explicit-function-return-type': ['off'] // 函数必须有返回值
    }
  }
]
